<?

if ($c = stack('name')) {

	$_id_component	= $DATA['components'][$c]['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value
	$_lang			= context('lang');
	
	$_crit = "id_data=$_id_data AND id_parent=$_id_component AND ".dbAndL('attr', AA_VISIBLE);

//	$s = array_extend( array('path' => 'sections', 'w' => 400, 'h' => 300, 'caption' => ''), $DATA['components'][$c]['settings']);

	$temp = array_mark_bounds( datafetch_array('db_list', array('table' => tb('data'), 'where' => "$_crit",	'order' => 'id_index', 'index' => 'id' )));



	$DATA['components'][$c]['meta'] = datafetch_array('db_list', array(
		'table' => tb('data'), 
		'where' => "id_data=$_id_meta AND id_parent in (".implode(',', array_keys($temp)).')',	
		'index' => 'id', 
	));
	
	foreach($DATA['components'][$c]['meta'] as $k => $v) {
		if ($v['assoc'])
			$temp[$v['id_parent']]['meta'][$v['name']][$v['assoc']] = $v['value'];
		else
			$temp[$v['id_parent']][$v['name']] = $v['value'];
	}

	$DATA['components'][$c]['data'] = array();
	
	foreach($temp as $k => $v) {

		if (isset($v['meta'])) 	// parse language dependent data
			foreach($v['meta'] as $mname => $mv) {
				if ($mv[$_lang] && ($mv[$_lang] != -1))
					$temp[$k][$mname] = $mv[$_lang];
				else {	// no data in current language, get any other we can find
					foreach($DATA['langs'] as $lid => $lv) {
						if ($mv[$lid] && ($mv[$lid] != -1)) {
							$temp[$k][$mname] = $mv[$lid];
							break;
						}
					}
				}
			}
			
		$DATA['components'][$c]['data'][$v['title']] = $temp[$k]['value'];
	}

/*
	$DATA['components'][$c]['data'] = array_mark_bounds( datafetch_array('db_list', array('table' => tb('data'), 'where' => "$_crit",	'order' => 'id_index', 'index' => 'id' )));



	$DATA['components'][$c]['meta'] = datafetch_array('db_list', array(
		'table' => tb('data'), 
		'where' => "id_data=$_id_meta AND id_parent in (".implode(',', array_keys($DATA['components'][$c]['data'])).')',	
		'index' => 'id', 
	));
	
	foreach($DATA['components'][$c]['meta'] as $k => $v) {
		if ($v['assoc'])
			$DATA['components'][$c]['data'][$v['id_parent']]['meta'][$v['name']][$v['assoc']] = $v['value'];
		else
			$DATA['components'][$c]['data'][$v['id_parent']][$v['name']] = $v['value'];
	}

	foreach($DATA['components'][$c]['data'] as $k => $v) {

		if (isset($v['meta'])) 	// parse language dependent data
			foreach($v['meta'] as $mname => $mv) {
				if ($mv[$_lang] && ($mv[$_lang] != -1))
					$DATA['components'][$c]['data'][$k][$mname] = $mv[$_lang];
				else {	// no data in current language, get any other we can find
					foreach($DATA['langs'] as $lid => $lv) {
						if ($mv[$lid] && ($mv[$lid] != -1)) {
							$DATA['components'][$c]['data'][$k][$mname] = $mv[$lid];
							break;
						}
					}
				}
			}
	}
*/
	
	unstack();
}